﻿using Prism.Events;
using Prism.Ioc;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace PrismEventAggregator01
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow(IEventAggregator eventAggregator)
        {
            InitializeComponent();

            eventAggregator.GetEvent<EventMessage>().Subscribe(Receive);

            eventAggregator.GetEvent<EventArgsMessage>().Subscribe(Receive);


            eventAggregator.GetEvent<EventArgsMessage>().Subscribe(Receive);





            eventAggregator.GetEvent<EventMessage>().Publish();
            Messenger.Defualt.GetEvent<EventArgsMessage>().Publish("1212121");


            // 1、先执行这里   发布
            Messenger.Defualt.GetEvent<EventArgsMessage>()
                .Publish(new EventAction()
                {
                    // 3、后面还有逻辑
                    ResultAction = new Action<bool>(state =>
                    {
                        // .......
                    })
                });
        }


        void Receive()
        {
            MessageBox.Show($"触发了无参函数");
        }

        void Receive(object obj)
        {
            MessageBox.Show($"触发了有参函数 {(string)obj} ");
        }
    }
}